'''
Created on 2009-7-24

@author: roy
'''

import time

from google.appengine.ext import db

class logMessage(db.Model):
    date = db.FloatProperty()
    content = db.StringProperty(multiline=True)
    
    
def addLog(txt):
    msg = logMessage(date=time.time(), 
                     content=txt)
    msg.put()
    
    
def deleteOld():
    earliest_date = time.time() - 3*24*3600
    q = db.GqlQuery("SELECT * FROM logMessage WHERE date < :1", earliest_date)
    results = q.fetch(100)
    db.delete(results)
    

def viewLog():
    earliest_date = time.time() - 3*24*3600
    q = db.GqlQuery("SELECT * FROM logMessage WHERE date > :1", earliest_date)
    results = q.fetch(100)
    count = len(results)
    print 'Content-Type: text/plain'
    print count
    for p in results:
        print "[%s]: %s" % (time.ctime(p.date), p.content)


if __name__ == '__main__':
    viewLog()    